<template xmlns="http://www.w3.org/1999/html">
  <sea-data-table ref="tableObject" url="/sys/log/log4j/list" :is-page="false" :table-height="536">
    <!--表头-->
    <sea-table-header slot="header" :display-form="false">
      <!--标题栏-->
      <sea-table-title slot="title" title="[slf4j] 系统运行日志"
                      subtitle="当前界面的按钮都可以点击，后台已经禁用了30天内文件的删除功能。"></sea-table-title>
    </sea-table-header>

    <!--表头-->
    <template slot="columns">
      <el-table-column label="日志文件">
        <a slot-scope="{row}" style="width: 100%;display: inline-block" @click="onAction('download', row)">
          <i class="fa fa-file-archive-o"></i> {{ row }}
        </a>
      </el-table-column>

      <!--操作栏-->
      <sea-table-actionbar width="180" :on-action="onAction" :buttons="buttons"></sea-table-actionbar>
    </template>
  </sea-data-table>
</template>

<script>

/**
 *
 * 系统访问日志
 */
export default {
    components: {}
    , data() {
        return {
            // 操作栏
            buttons: [
                {type: 'btn', evt: 'download', label: '下载', title: '下载当前文件'}
                , {type: 'divider'}
                , {type: 'btn', evt: 'del', label: '删除', style: 'text-orange', title: '删除当前行'}
            ]
            // end--
        }
    }
    , methods: {
        /**
         * 操作栏事件分发
         * @param evt 事件
         * @param row 行级对象
         * @param old 可供回滚的参数
         */
        onAction: function (evt, row, old) {
            if (evt === 'download') {
                window.open(this.layers.getContextPath() + '/sys/log/log4j/download?filename=' + encodeURI(row));
            } else if(evt === 'del'){
                this.$layers.delete({
                    url: '/sys/log/log4j/info'
                    , method: 'DELETE'
                    , params: {filename: row}
                }).then((ret) => {
                    if (ret.code === 0) {
                        this.$layers.succeed();
                    }
                });
            }
        }
    }
}
</script>
